{echo:JS::import("form")}
{echo:JS::import('dialog?skin=tinysimple');}
{echo:JS::import('dialogtools');}
<link type="text/css" rel="stylesheet" href="{url:#css/ucenter.css}" />
<style type="text/css">
/*td{text-align:center;}*/
</style>
<div class="container clearfix">
	{widget:name=sub_navs action=ucsidebar sidebar=$sidebar act=$actionId}
	<div class="content clearfix uc-content">
	
		
		<div class="mt10 tab">
			<ul class="tab-head">
				<li>交易大厅<i></i></li>
			</ul>
			
			<div class="box p15 mt10 clearfix"> 
				<span class="fl">
					<a href="#">按时间排序▲</a>&nbsp;|&nbsp;
					<a href="#">按价格排序▲</a>&nbsp;&nbsp;
					<a href="javascript:;" id="zh-btn" class="btn btn-main btn-mini">我要卖出</a>
					<!-- 
					&nbsp;&nbsp;
					<a href="javascript:;" id="withdraw-btn" class="btn btn-main btn-mini">我要买进</a>
					-->
					
				</span>
			</div>
			
			<div class="tab-body" style="margin-top:-5px;">
			
			
			
				<!-- 提现 -->
				<div>
					<table class="simple">
						<tr>
							<th>卖家</th>
							<th>时间</th>
							<th>单价</th>
							<th>数量</th>
							<th>总金额</th> 
							<th>交易说明</th> 
							<th>操作</th>
						</tr>
						{query:name=transaction_sell as t fields=t.*,u.name as uname join=inner join user as u where t.user_id eq u.id order=t.id desc page=1 id=$withdraw}
						<tr class="{if:$key%2==1}odd{else:}even{/if} {if:$item['status']==2}noborder{/if}">
							<td>{$item['uname']}</td> 
							<td>{$item['create_time']}</td>
							<td>{$item['price']}</td>
							<td>{$item['last_quantity']}</td>
							<td>{echo:$item['last_quantity']*$item['price']}</td>
							<td>{$item['desc']}</td> 
							<td>
								{if:$item['status']==0}
									<!-- 
									<a class="btn btn-main">撤销</a>
									-->
									<!-- 
									<b style="color:green;">可买入</b>
									-->
									<a href="javascript:;" id="withdraw-btn" sell_id="{$item['id']}" class="btn btn-main btn-mini">我要买入</a>
								{else:}
									<b style="color:red;">已抢完</b>
								{/if}
							</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav f12">{echo:$withdraw->pagebar()}</div>
				</div>
				
			</div>
		</div>
	</div>
</div>












<div id="zh-dialog" class="hidden">
	<!-- 
	<table class="simple">
		<tr><td>现金币</td><td>借款币</td><td>购物币</td><td>重消币</td><td>信用币</td><td>学习币</td></tr>
		<tr class="red"><td>{$customer['balance']|'0.00'}</td><td>{$customer['jkb']|'0.00'}</td><td>{$customer['gwb']|'0'}</td><td>{$customer['cx']|'0.00'}</td><td>{$customer['xyb']|'0'}</td><td>{$customer['xxb']|'0'}</td></tr>
	</table>
	-->
	<form id="zh_form" action="{url:/ucenter/sell_ok_xfjf}" method="post" target="_blank" callback="submit_sell_ok_xfjf">
		<table class="form" style="width:550px;margin-top:0px;">
			<tr>
				<td>可用积分：</td>
				<td>
					<b style="color:red;">{$currency_symbol}{$user['ok_xfjf']}</b>				
				</td>
			</tr>
			<tr>
				<td>卖出数量：</td>
				<td>
					<input type="text" name="quantity" id="quantity" pattern="int" min="100" alt="卖出数量必须为100的倍数" placeholder="卖出数量需为100的倍数"/>				
				</td>
			</tr>
			<tr>
				<td>卖出单价：</td>
				{set:$ok_xfjf_price1=Common::getConfigJjsetValue('jjset_ok_xfjf_price1')}
				{set:$ok_xfjf_price2=Common::getConfigJjsetValue('jjset_ok_xfjf_price2')}
				<td><input type="text" name="price" id="price" pattern="float" min='{$ok_xfjf_price1}' max="{$ok_xfjf_price2}" alt="卖出价格范围{$ok_xfjf_price1}-{$ok_xfjf_price2}" placeholder="卖出价格范围{$ok_xfjf_price1}-{$ok_xfjf_price2}"> <label></label></td>
			</tr>
			<tr>
				<td>交易密码：</td>
				<td><input type="password" name="pass2" id="pass2" pattern="required" alt="输入交易密码"> <label></label></td>
			</tr>
			<tr>
				<td>交易说明：</td>
				<td><input type="text" name="desc" id="desc"> <label></label></td>
			</tr>
			<tr>
				<td colspan="2" class="tc"><input type="submit" id="btn_sell_ok_xfjf" class="btn btn-main" value="提交"></td>
			</tr>
		</table>
	</form>
</div>





<div  id="withdraw-dialog" class="hidden">
	<form id="withdraw_form" action="{url:/ucenter/buy_ok_xfjf}" method="post" target="_blank" callback="submit_buy_ok_xfjf">
		<table class="form" style="width:600px;">
			<tr>
				<td class="label">账户金额：</td>
				<td> <label class="f18 red">{$currency_symbol}{$user['balance']}</label></td>
			</tr>
			<!-- 
			<tr>
				<td class="label">提现金额：</td>
				<td><input type="text" id="w_amount" name="amount" class="small"  pattern="float" min="100" max="{$customer['balance']}" alt="提现金额至少为100元"> <label></label></td>
			</tr>
			<tr>
				<td class="label">姓名：</td>
				<td><input type="text" id="w_name" name="name"  pattern="required" alt="开户对应的用户名"> <label></label></td>
			</tr>
			<tr>
				<td class="label">金融机构：</td>
				<td><input type="text" id="w_type_name" name="type_name"  pattern="required" alt="如（支付宝、中国银行）"> <label></label></td>
			</tr>
			-->
			<tr>
				<td class="label">买入数量：</td>
				<td><input type="text" id="buy_quantity" name="buy_quantity"  pattern="int" min="1" alt="买入数量至少为1"> <label></label></td>
			</tr>
			<tr>
				<td  class="label">交易密码：</td>
				<td><input type="password" name="buy_pass2" id="buy_pass2" pattern="required" alt="输入交易密码"> <label></label></td>
			</tr>
			<tr>
				
				<td colspan="2" class="tc">
					<input id="hid_sell_id" name="hid_sell_id" type="hidden"/>
					<input type="submit" id="btn_buy_ok_xfjf" class="btn btn-main" value="提交">
				</td>
			</tr>
		</table>
	</form>
</div>
				



<script type="text/javascript">

	$("#recharge-btn").on("click",function() {
		art.dialog({id:'recharge-dialog',title:'在线充值',content:document.getElementById('recharge-dialog'),lock:true});
	});
	$("#withdraw-btn").on("click",function() {
		$("#hid_sell_id").val($(this).attr('sell_id'));
		art.dialog({id:'withdraw-dialog',title:'我要买入',content:document.getElementById('withdraw-dialog'),lock:true});
	});
	$("#zh-btn").on("click",function() {
		art.dialog({id:'zh-dialog',title:'我要卖出',content:document.getElementById('zh-dialog'),lock:true});
	});
	$("#zz-btn").on("click",function() {
	art.dialog({id:'zz-dialog',title:'转账',content:document.getElementById('zz-dialog'),lock:true});
});
	function close_dialog(e){
		if(!e)art.dialog({id:'recharge-dialog'}).close();
	}
	function submit_buy_ok_xfjf(e){
		
		if(!e){
			var quantity = $.trim($("#buy_quantity").val());
			//var price = $.trim($("#buy_price").val());
			var pass2 = $.trim($("#buy_pass2").val());
			var sell_id = $("#hid_sell_id").val();
			
			$("#btn_buy_ok_xfjf").attr("disabled", true);	
			
			$.get("{url:/ucenter/buy_ok_xfjf}",{sell_id:sell_id,quantity:quantity,pass2:pass2},function(data){
				if(data['status']=='success'){
					art.dialog({id:'withdraw-dialog'}).close();
					art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>",2);
            		setTimeout("tools_reload()",2000);
					//window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-3";
            		window.location.href = "{url:/ucenter/transaction_list}";
				}else{
					alert(data['msg']);
					$("#btn_buy_ok_xfjf").attr("disabled", false);
				}
			},'json');
		}
		return false;
	}
	function submit_sell_ok_xfjf(e){
		
		if(!e){
			var quantity = $.trim($("#quantity").val());
			var price = $.trim($("#price").val());
			var pass2 = $.trim($("#pass2").val());
			var desc  = $.trim($("#desc").val());
			
			$("#btn_sell_ok_xfjf").attr("disabled", true);
			
			$.get("{url:/ucenter/sell_ok_xfjf}",{quantity:quantity,price:price,pass2:pass2,desc:desc},function(data){
				if(data['status']=='success'){
					art.dialog({id:'zh-dialog'}).close();
					art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>",2);
            		setTimeout("tools_reload()",2000);
					//window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-2";
            		window.location.href = "{url:/ucenter/transaction_list}";
				}else{
					alert(data['msg']);
					$("#btn_sell_ok_xfjf").attr("disabled", false);
				}
			},'json');
		}
		return false;
	}
	function submit_zz(e){
	if(!e){
		var fields = $("#zz_form").serializeArray();
		$.get("{url:/ucenter/zz}",fields,function(data){
			if(data['status']=='success'){
				art.dialog({id:'zz-dialog'}).close();
				art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>",2);
            setTimeout("tools_reload()",2000);
            window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-1";
			}else{
				alert(data['msg']);
			}
		},'json');
	}
	return false;
}
	
</script>
